""" player - Player class """

import logging

class Player(object):
    """
    Represents an active player in the current game.
    """
    
    rank = None
    boss = None
    boats = None
    money = 0
    reputation = 0
    plotCallback = None
    game = None
    world = None
    
    log = logging.getLogger('pgame.engine.player')
    
    def __init__(self, game, world):
        self.game = game
        self.world = world
        self.boats = []
        self.boatsThisTurn = []
        
    def move(self):
        """
        Execute the boat movement plotted.
        """
        for boat in self.boats:
            boat.move()
        
    def startTurn(self):
        """
        Get ready for a new turn.
        """
        self.log.debug('Starting a turn.')
        self.boatsThisTurn = []
        for boat in self.boats:
            boat.startTurn()
        if not len(self.boatsThisTurn):
            self.finishTurn()
                
    def onBoatStarted(self, boat):
        """
        Keep track of started boats for this turn.
        """
        assert boat not in self.boatsThisTurn
        self.boatsThisTurn.append(boat)
            
    def onBoatRestarted(self, boat):
        """
        Keep track of started boats for this turn.
        """
        assert boat not in self.boatsThisTurn
        self.boatsThisTurn.append(boat)
        
        
    def onBoatFinished(self, boat):
        """
        Keep track of finished boats for this turn.
        """
        assert boat in self.boatsThisTurn
        self.boatsThisTurn.remove(boat)
        if len(self.boatsThisTurn) == 0:
            self.finishTurn()
            
    def finishTurn(self):
        """
        Complete a turn.
        """
        self.game.onPlayerFinished(self)

